<template>
  <div>
    <el-row>
      <el-col :span="16" style="border-right: 3px solid #dcdfe6; padding-right: 5px">
        <withTable :tFId="tFId" :tableConfig="props.params" ref="tableRef"
          :userParams="{  methodId: props.methodId }"
          :formulaParams="{ tableId: props.params.tableId }" />
      </el-col>
      <el-col :span="8" style="padding-left: 5px">
        <p class="pinformation">基本信息</p>
        <el-row>
          <el-form-item label="标曲表名称：" label-width="90">
            {{ lineForm.lineTitle }}
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="模板：" label-width="90">
            {{ lineForm.tableName }}
          </el-form-item>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="创建人：" label-width="90">
              {{ lineForm.createUserName }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态：" label-width="90">
              {{ lineForm.statusName }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="有效时间：" label-width="90">
            {{ lineForm.createDate }} 至 {{ lineForm.yxDate }}
          </el-form-item>
        </el-row>
        <el-row>
          <p class="pinformation">标样列表</p>
          <p class="totalStyle">共
            <template v-if="lineForm.labLineSampleList">{{ lineForm.labLineSampleList.length }} </template>
            <template v-else>0</template>
            条数据
          </p>
        </el-row>
        <el-table :data="lineForm.labLineSampleList" v-loading="loading" max-height="20vw">
          <el-table-column show-overflow-tooltip label="标样编号" align="center" prop="code" />
          <el-table-column label="检测项目" align="center" prop="jcxmName">
            <template #default="scope">
              <span v-html="proxy.getSupAndSub(scope.row.jcxmName)"></span>
            </template>
          </el-table-column>
        </el-table>
        <el-row>
          <p class="pinformation">谱图列表</p>
          <p class="totalStyle">共
            <template v-if="lineForm.fileList">{{ lineForm.fileList.length }} </template>
            <template v-else>0</template>
            条数据
          </p>
        </el-row>
        <el-row style="padding-left: 10px;">
          <fileUpload v-model="lineForm.fileList" :isDisplay="false" v-if="lineForm.fileList && lineForm.fileList.length"
            :isLocal="true"></fileUpload>
        </el-row>
        <el-row style="padding-left: 10px;">
          <el-button type="success"
            v-if="props.params.userStatus == 0 && props.params.userStepId == 0 && props.params && props.params.isRead == 0"
            @click="editBqb">调整标准曲线</el-button>
          <el-button type="danger" @click="handleDeleteLine"
            v-if="props.params.userStatus == 0 && props.params.userStepId == 0">删除标准曲线</el-button>
        </el-row>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { nextTick } from "vue";
import withTable from "./withTable.vue";
import bus from "@/utils/eventBus";
import {
  getLineInfo,
  deleteLine
} from "@/api/lab/labMethod";
const { proxy } = getCurrentInstance();
const tFId = ref("");
const lineForm = ref({});
const loading = ref(false);
const tableRef = ref(null)
const props = defineProps({
  params: {
    type: Object,
    required: true,
  },
  lMId: {
    type: String,
  },
  methodId: {
    type: String
  }
});

nextTick(() => {

  tFId.value = props.params.tFId;
  loading.value = true;
  getLineInfo(props.params.formId).then(res => {
    lineForm.value = res.data;
    loading.value = false;
  });
});

function getInfo() {
  getLineInfo(props.params.formId).then(res => {
    lineForm.value = res.data;
    loading.value = false;
  });
}

function getTable(params) {
  tableRef.value.showTable()
}

function handleDeleteLine() {
  proxy.$modal.confirm('确认要删除当前的标准曲线表吗？').then(function () {
    return deleteLine(tFId.value);
  }).then(() => {
    bus.emit("deleteTabView", tFId.value)
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => { });
}

const emit = defineEmits(["editBq"])

function editBqb() {
  emit("editBq", lineForm.value.lineId)
}

defineExpose({
  getInfo,
  getTable
});
</script>

<style lang="scss" scoped>
:deep(.el-form-item) {
  margin-bottom: 0px !important;
}
</style>